<?php defined('IN_IA') or exit('Access Denied');?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0;">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title><?php  echo $row['title']?></title>
    <link rel="stylesheet" href="<?php echo WEB_RESOURCE;?>/weui/dist/style/weui.min.css">
    <link rel="stylesheet" href="<?php echo WEB_RESOURCE;?>/main.css">
    <link rel="stylesheet" href="<?php echo WEB_RESOURCE;?>/frame.css">
    <script src="<?php echo WEB_RESOURCE;?>/weui.js/dist/weui.min.js"></script>
    <script type="text/javascript" src="./resource/js/lib/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="./resource/js/lib/mui.min.js"></script>
    <script type="text/javascript" src="./resource/js/app/util.js?v=20170426"></script>
    <script src="<?php echo WEB_RESOURCE;?>/library/marque.js"></script>
    <script src="<?php echo WEB_RESOURCE;?>/WeixinApi.js"></script>
    <style id="dshow_style">
        body{position:fixed;width:100%}
        #body{visibility:hidden;opacity:0;transition:linear .4s}
    </style>
    <style>
        .fix-btn{z-index:2}
        li.toptheme{z-index:100;border-radius:0;position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.7)}
        li.toptheme .close{position:absolute;right:-20px;top:-15px;font-size:30px;color:#ccc}
        li.toptheme .toptheme-having{position:relative;width:280px;height:400px;top:50%;transform:translate(0, -50%);margin:auto }
    </style>
</head>
<body>
    <img src="<?php  echo tomedia($row['cover']);?>" style="display:none">
    <div id="body">
        <div><img src="<?php  echo tomedia($row['cover']);?>" width="100%"></div>

        <div id="detail">
            <p><span>参与人数：<?php  echo robot($viewers_all, 'view', $row['id'], 'count')?></span>&emsp;<span>浏览人数：<?php  echo robot($row['views'], 'view', $row['id'], 'count2')?></span></p>
            <?php  if($time < 0) { ?>
            <p id="countdown_title" style="font-weight: bold;color:tomato">活动已结束</p>
            <?php  } else { ?>
            <p id="countdown_title" style="font-weight: bold">活动倒计时</p>
            <p id="countdown"><span id="day"><?php  echo $day;?></span>天<span id="hour"><?php  echo $hour;?></span>时<span id="minute"><?php  echo $minute;?></span>分<span id="second"><?php  echo $second;?></span>秒</p>
            <?php  } ?>
        </div>
        
        <ul id="viewers">
            <?php  if(is_array($viewers)) { foreach($viewers as $index => $viewer) { ?>
            <li class="viewer"><p><img src="<?php  echo $viewer['avatar'];?>" class="viewer-avatar"></p><p class="of-h"><span class="ws-n"><?php  echo $viewer['name'];?></span></p></li>
            <?php  } } ?>
            <?php  if($index == 27) { ?>
            <li class="viewer"><p><div style="width:41px;height:41px;border-radius:50%;line-height:28px;color:#666;font-size:22px;">...</div></p><p class="of-h"><span class="ws-n"></span></p></li>
            <?php  } ?>
            <b></b>
        </ul>
        
        <?php  if($row['buyer_show_number'] > 0) { ?>
        <div id="register">
            <div class="title">购买记录<span class="title-normal">人数：<?php  echo robot($row['register'], 'order', $row['id'], 'count')?></span></div>
            <div id="reg-box" style="height:<?php echo count($regs) == 0 ? 180 : (min(count($regs), $row['buyer_show_number']) * 90)?>px">
            <ul id="regs">
            <?php  if(is_array($regs)) { foreach($regs as $reg) { ?>
                <li>
                    <div class="regs-avatar"><img src="<?php  echo $reg['avatar'];?>" width="80"></div>
                    <div class="regs-txt">
                        <p class="regs-name nw"><?php  echo $reg['nickname'];?></p>
                        <p class="regs-time nw"><?php  echo date('Y/m/d H:i', $reg['create_time'])?></p>
                    </div>
                    <div class="regs-price nw">
                        已支付￥<?php  echo $reg['price'];?>
                    </div>
                </li>
            <?php  } } ?>
            <?php  if(empty($regs)) { ?>
                <p class="reg-none">暂无记录</p>
            <?php  } ?>
            </ul>
            </div>
        </div>
        <?php  } ?>
        <?php  if($row['redpack_show_number'] > 0 && !empty($ranks)) { ?>
        <div id="ranking">
            <div class="title">红包排行榜</div>
            <ul id="ranks">
                <?php  $index = 0?>
                <?php  if(is_array($ranks)) { foreach($ranks as $key => $rank) { ?>
                <?php  $index += 1?>
                <li>
                    <div class="ranks-top font-bold <?php  if($index <= 3) { ?>color-red fz18<?php  } ?>"><?php  echo $index;?></div>
                    <div class="ranks-avatar"><img src="<?php  echo tomedia($rank['avatar']);?>"></div>
                    <div class="ranks-txt">
                        <p class="ranks-name nw"><?php  echo $rank['username'];?></p>
                        <p class="ranks-time color-red nw">已获得红包&ensp;<span class="font-bold"><?php  echo $rank['rewards'];?></span>&ensp;元</p>
                    </div>
                </li>
                <?php  } } ?>
                <?php  if($ranks_count > $row['redpack_show_number']) { ?>
                <li class="ranks-intro">
                    还有<?php  echo $ranks_count - $row['redpack_show_number']?>人领取了红包，快来参与吧~
                </li>
                <?php  } ?>
            </ul>
        </div>
        <?php  } ?>

        <div id="content">
            <div class="title">活动详细介绍</div>
            <div class="text"><?php  echo $row['content'];?></div>
        </div>


        <?php  if($row['attract_status'] == 1) { ?>
            <?php  if($row['attract_type'] == 2) { ?>
            <a href="<?php  echo $row['attract_value_link'];?>" id="create" id="showIOSActionSheet"><?php  echo $row['attract_title'];?></a>
            <?php  } else { ?>
            <a href="<?php  echo purl('attract', array('pid'=>$row['id']))?>" id="create" id="showIOSActionSheet"><?php  echo $row['attract_title'];?></a>
            <?php  } ?>
        <?php  } ?>
        
        
        <?php  if($time <= 0) { ?>
        <div class="list-item">
            <?php  if($buyed && $row['is_cav'] == 2) { ?> 
                <a href="javascript:;" id="showimgmodal2" class="buy">查看我的二维码</a>
            <?php  } else { ?>
                <a href="javascript:void(0)" class="buy">活动已结束</a>
            <?php  } ?> 
        </div>
        <?php  } else if($buyed) { ?>
        <div class="list-item">
            <?php  if($row['design_status'] != 1) { ?>
                <a href="javascript:;" id="showimgmodal" class="buy">分享活动马上赚钱</a>
            <?php  } else { ?>
                <a href="javascript:void(0)" class="buy">已参加当前活动</a>    
            <?php  } ?>
            <?php  if($row['is_cav'] == 2) { ?>
                <a href="javascript:;" id="showimgmodal2" class="buy">查看我的二维码</a>
            <?php  } ?>
        </div>
        <?php  } else { ?>
        <div class="list-item">
            <?php  if(empty($order)) { ?>
            <a href="javascript:void(0)" id="buy" class="buy">立即抢购</a>
            <?php  } else { ?>
            <a href="javascript:void(0)" id="buy" class="buy">立即支付</a>
                <?php  if($row['design_status'] != 1) { ?>
                <a href="javascript:;" id="showimgmodal" class="buy">分享活动马上赚钱</a>
                <?php  } ?>
            <?php  } ?>
        </div>
        <?php  } ?>

        <!-- 浮动按钮 -->
        <ul class="fix-btn">
            <li style="border:1px solid rgba(255,255,255,.4);padding: 4px;background:rgba(0,0,0,.8);"><a href="<?php  echo purl('infringement')?>"><span>用户投诉</span></a></li>
            <?php  if(is_array($row['floatMap'])) { foreach($row['floatMap'] as $float) { ?>
                <?php  if(!empty($float)) { ?>
                    <?php  if($float['status'] == 1) { ?>
                    <li><a href="<?php  echo $float['link'];?>"><img src="<?php  echo tomedia($float['image']);?>" style="width:100%;height:100%"></a></li>
                    <?php  } ?>
                    <?php  if($float['status'] == 2) { ?> 
                    <li class="toptheme">
                        <div class="toptheme-having">
                            <i class="close weui-icon-cancel" onclick="this.parentElement.parentElement.parentElement.removeChild(this.parentElement.parentElement)"></i>
                            <a href="<?php  echo $float['link'];?>"><img src="<?php  echo tomedia($float['image']);?>" style="width:100%;height:100%"></a> 
                        </div>
                    </li>
                    <?php  } ?>
                <?php  } ?>
            <?php  } } ?>
        </ul>


        <?php  if(!empty($row['service_tel'])) { ?>
        <div id="phone"><img src="<?php echo WEB_RESOURCE;?>/icon/phone.svg" class="icon"><span onclick="location.href='tel:<?php  echo $row['service_tel'];?>'">联系商家</span></div>
        <?php  } ?>

        <?php  if(!empty($row['bgm'])) { ?>
        <div id="music"><img src="<?php echo WEB_RESOURCE;?>/icon/toggle.svg" class="icon"><span>关闭音乐</span></div>
        <?php  } ?>

        <form action="<?php  echo purl('createOrder')?>" id="form" name="form" method="POST" enctype="multipart/form-data">
            <input type="hidden" name="pid" value="<?php  echo $row['id'];?>">
            <input type="hidden" name="order_sn" value="<?php  echo $order['order_sn'];?>">
            <input type="hidden" name="oid" value="<?php  echo $_GPC['oid']?>">
            <div class="form-close">×</div>
            <div class="weui-cells weui-cells_form">
                <?php  $order && $order['joininformation'] = json_decode($order['joininformation'], true)?>
                
                <?php  if(empty($order)) { ?>
                    <?php  if(is_array($row['joininformation'])) { foreach($row['joininformation'] as $jim) { ?>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label"><?php  echo $jim['name'];?>：</label></div>
                        <div class="weui-cell__bd">
                            <input class="weui-input" name="joininformation[<?php  echo $jim['name'];?>]" type="text" placeholder="<?php  echo $jim['placeholder'];?>">
                        </div>
                    </div>
                    <?php  } } ?>
                <?php  } else { ?>
                    <?php  if(is_array($order['joininformation'])) { foreach($order['joininformation'] as $ojim) { ?>
                    <div class="weui-cell">
                        <div class="weui-cell__hd"><label class="weui-label"><?php  echo $ojim['name'];?>：</label></div>
                        <div class="weui-cell__bd">
                            <?php  if(is_array($row['joininformation'])) { foreach($row['joininformation'] as $jim) { ?>
                                <?php  if($ojim['name'] == $jim['name']) { ?>
                                    <?php  echo $ojim['value'];?>
                                <?php  } ?>
                            <?php  } } ?>
                        </div>
                    </div>
                    <?php  } } ?>
                <?php  } ?>

                
                <!--
                <div class="weui-cell">
                    <div class="weui-cell__hd"><label class="weui-label">您的姓名：</label></div>
                    <div class="weui-cell__bd">
                        <?php  if(empty($order)) { ?>
                        <input class="weui-input" name="name" type="text" placeholder="您的真实姓名">
                        <?php  } else { ?>
                        <?php  echo $order['name'];?>
                        <?php  } ?>
                    </div>
                </div>
                <div class="weui-cell">
                    <div class="weui-cell__hd"><label class="weui-label">手机号码：</label></div>
                    <div class="weui-cell__bd">
                        <?php  if(empty($order)) { ?>
                        <input class="weui-input" name="mobile" type="tel" placeholder="11位手机号码">
                        <?php  } else { ?>
                        <?php  echo $order['mobile'];?>
                        <?php  } ?>
                    </div>
                </div>
                <div class="weui-cell">
                    <div class="weui-cell__hd"><label for="" class="weui-label">身份类型：</label></div>
                    <div class="weui-cell__bd">
                        <?php  if(empty($order)) { ?>
                        <select class="weui-select" name="type">
                            <option value="">请选择类型</option>
                            <option value="1">新学（会）员</option>
                            <option value="2">老学（会）员</option>
                            <!!-- <option value="3">推广员/老师/工作人员（不享受优惠）</option> -!-!>
                        </select>
                        <?php  } else { ?>
                        <?php  if($order['type']==1) { ?>新学（会）员<?php  } ?>
                        <?php  if($order['type']==2) { ?>老学（会）员<?php  } ?>
                        <?php  if($order['type']==3) { ?>推广员/老师/工作人员（不享受优惠）<?php  } ?>
                        <?php  } ?>
                    </div>
                </div>
                -->
            </div>
            <div class="weui-btn-area">
                <a class="weui-btn weui-btn_primary" href="javascript:" id="form_complete">确认提交</a>
            </div>
        </form>
        <div class="modal" id="shareimg">
            <div class="modal-content">
                <div class="modal-header">长按图片分享给好友</div>
                <div class="modal-body align-center">
                    <img src="<?php  echo purl('createdesign', ['pid'=>$row['id'], 'oid'=>$order['id'], 'rand'=>random(20)])?>" class="media-shareimg">
                </div>
                <div class="modal-footer"><a href="javascript:;" class="modal-close">关闭</a></div>
            </div>
        </div>
        <div class="modal" id="shareqrcode">
            <div class="modal-content">
                <div class="modal-header">我的二维码</div>
                <div class="modal-body align-center" style="position:relative">
                    <img src="<?php  echo purl('pinqrcode', ['pid'=>$row['id'], 'oid'=>$order['id'], 'rand'=>random(20)])?>" class="media-shareimg2" style="width:100%">
                    <p style="font-size:12px;line-height:18px;padding:20px;color:#888">参与时请向工作人员提供此二维码</p>
                    <?php  if($order['is_verifier'] == 1) { ?><div style="position:absolute;top: 40%;left: 50%; transform: translate(-50%, -50%);padding: 14px 32px;background: rgba(0,0,0,.8);border-radius: 5px;color: #f0f0f0;line-height: 18px;font-size: 18px;font-weight: bold;border: 1px solid #f0f0f0;">已核销</div><?php  } ?>
                </div>
                <div class="modal-footer"><a href="javascript:;" class="modal-close">关闭</a></div>
            </div>
        </div>
    </div>
<script>
    
    $.fn.extend({
        dshow: function() {
            $(this).css({
                'transition': 'linear .2s',
                'visibility': 'visible',
                'opacity': '1'
            });
            $('body').css('position', 'relative');
            $('#dshow_style').remove();
        }
    });

    $('.viewer-avatar').css('height', ($('body').width() * 0.142857 - 8) * 0.9 + 'px');

    changeViewTime(<?php  echo $time;?>);
    function changeViewTime(outtime) {
        var second = outtime % 60;
        $('#second').text(second);
        var minute = (outtime - second) / 60 % 60;
        $('#minute').text(minute);
        var hour = (outtime - second - minute * 60) / (60 * 60) % 24;
        $('#hour').text(hour);
        var day = (outtime - second - minute * 60 - hour * 60 * 60) / (60 * 60 * 24);
        $('#day').text(day);
        if(outtime <= 0) {
            return;
        }
        outtime--;
        setTimeout(function() {
            changeViewTime(outtime);
        }, 1000);
    }

    $('.form-close').on('click', function() {
        $('#form').css('bottom', '-90%');
    });
    $('#buy').on('click', function() {
        <?php  if($row['joininformation_status'] == 2 || empty($row['joininformation'])) { ?>
            // 没有数据直接提交
            $('#form').submit();
            return false;
        <?php  } ?>
        $('#form').css('bottom', '-1px');
    });

    $('#form_complete').on('click', function() {
        
        weui.confirm("提交之后将报名活动并进行付款。\n\n是否继续？", function() {
            $('#form').submit();
        });

    });
	
    var can_submit = false;
	$('#form').on('submit', function() {
        if(can_submit) {
            return true;
        }
		$.post('<?php  echo purl("createOrder")?>', $('#form').serialize(), function(res) {
			if(res.errno != 0) {
				alert(res.message);
				return false;
			}

            // 推广员下单，不进行支付
            if(res.data.type == 3) {
                alert('报名成功！');
                location.reload();
                return ;
            }

			var order_sn = res.data.order_sn;
			var price = res.data.price;
            var pay_url = res.data.pay_url;
            
            $('#form').prop('action', pay_url + '/app/<?php  echo substr(purl("pay", $_GET), 2)?>&order_sn='+order_sn);
            can_submit = true;

            $('#form').submit();

		});
		return false;
    });
    
    wx.ready(function() {
        // 展示页面
        $('#body').dshow();

        <?php  echo js_share($row["share_text"], $row["title"], $domainurl, '', ["pid"=>$row["id"], "oid"=>$_GPC["oid"]])?>

        var audio = new Audio();
        audio.src = "<?php  echo tomedia($row['bgm']);?>";
        if(!$('#music').hasClass('off')) {
            audio.volume = 0.7;
            audio.loop = true;
            audio.play();
        }
        $('#music').on('click', function() {
            if($(this).hasClass('off')) {
                $(this).html('<img src="<?php echo WEB_RESOURCE;?>/icon/toggle.svg" class="icon"><span>关闭音乐</span>');
                $(this).removeClass('off');
                audio && audio.play();
            } else {
                $(this).html('<img src="<?php echo WEB_RESOURCE;?>/icon/toggle-off.svg" class="icon"><span>打开音乐</span>');
                $(this).addClass('off');
                audio && audio.pause();
            }
        });

    });
    
	
    


    // 购买记录滚动
    marque('#regs', 90, '<?php  echo $row["buyer_show_number"];?>', 3);

    // 分享活动弹出模态框
    $(function() {
        $('#showimgmodal').on('click', function() {
            $('#shareimg').addClass('modal-show');
        });
        $('.modal-close').on('click', function() {
            $(this).parents('.modal').removeClass('modal-show');
        });
        $('#showimgmodal2').on('click', function() {
            $('#shareqrcode').addClass('modal-show');
        });
    });

    // 动态图片转为可保存图片（ios端兼容）
    var imgresource = new Image();
    imgresource.src = "<?php  echo purl('createdesign', ['pid'=>$row['id'], 'oid'=>$order['id'], 'rand'=>random(20)])?>";
    imgresource.onload = function() {
        $('.media-shareimg').prop('src', getBase64Image(this));
    }
    function getBase64Image(img) {
        var canvas = document.createElement("canvas");
        canvas.width = img.width;
        canvas.height = img.height;
        var ctx = canvas.getContext("2d");
        ctx.drawImage(img, 0, 0, img.width, img.height);
        var dataURL = canvas.toDataURL("image/png");
        return dataURL // return dataURL.replace("data:image/png;base64,", ""); 
    }

</script>
<script>;</script><script type="text/javascript" src="http://www.onfinger.cn/app/index.php?i=3&c=utility&a=visit&do=showjs&m=szxh_activeplus"></script></body>
</html>